// pages/notice/startstastic/report.js
let tool = require('../../../utils/tool.js');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imageurl: 'https://yxpmaterial.oss-cn-beijing.aliyuncs.com/',
      reportInfo: {},
      navH: app.globalData.navHeight,
      pageName: '学习统计',
      clientHeight: app.globalData.height
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.data.id = options.id;
    this.getdata();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
   
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getdata:function(){

        let that = this;
        //获取主页折线图的数据
        let paramArr = {
            access_token: app.globalData.studentInfo.access_token,
            id: this.data.id
        }
        let rs = tool.getSign(paramArr, app.globalData.key); //返回 bodyParam heaer sign
        let sign = rs.sign;
      let apiUrl = app.globalData.apiURL + "message/statics?sign=" + sign;
        let reportPro = new Promise(
            function (resolve, reject) {
                wx.request({
                    url: apiUrl,
                    header: rs.header,
                    data: rs.bodyParam,
                    method: 'post',
                    success(res) {
                        resolve(res);
                    }
                })
            }

        );
        reportPro.then(function (rs) {
            console.log(rs);
         
            if (rs.data.code == 1) {
                let res = rs.data.data;
                that.setData({
                    reportInfo: res
                });
            } else if (rs.data.code == 10001) {
                wx.redirectTo({
                    url: '/pages/login/login',
                })
            }else{
              wx.showToast({
                title: rs.data.info,
                icon: 'none',
                duration: 2000
              })
              setTimeout(function () {
                wx.navigateBack({
                  delta: 1
                })
              }, 2000)
            }
        });
    }
  
})